/**
 * Form Layout by Karla.
 * Functional coding by Karla.
 */

package Forms;
import java.sql.*;
import java.util.*;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import teComponents.*;

import com.toedter.calendar.JDateChooser;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import Classes.*;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CustomerForm  extends teComponents.teJinternalFrame {
	private teJList lstAll;
    private DefaultListModel listModel;
    private Vector<String> cv;
	private teJButton btnGo;
	private teJTextField txtsearchDesc;
	private teJButton btnUnassigned;
	private teJLabel lblShowInactive;
	private teJButton btnCC;
	private teJLabel lblFName;
	private teJLabel lblLName;
	private teJLabel lblID;
	private teJLabel lblAddress;
	private teJLabel lblCountry;
	private teJLabel lblPC;
	private teJLabel lblProv;
	private teJLabel lblCity;
	private teJLabel lblBPhone;
	private teJLabel lblHPhone;
	private teJLabel lblEmail;
	private teJLabel lblAgent;
	private teJComboBox cboAgent;
	private teJTextField txtEMail;
	private teJTextField txtBPhone;
	private teJTextField txtHPhone;
	private teJTextField txtCountry;
	private teJTextField txtPC;
	private teJTextField txtProv;
	private teJTextField txtCity;
	private teJTextField txtAddress;
	private teJTextField txtFName;
	private teJTextField txtLName;
	private teJTextField txtCustID;
	private teJButton btnPmts;
	private teJLabel lblsearchDesc;
	private teJLabel lblsearchName;
	private teJPanel pnlSearch;
	private teJLabel lblSelectedPanel;
	private JCheckBox chkSearchInactive;
	private JPanel pnlSelected;
	private teJButton btnAdd;
	private JCheckBox chkInactive;
	private teJLabel lblInactive;
	private JDateChooser jDateChooser1;
	private teJButton btnUpdate;
	private teJButton btnClear;
	private teJButton btnDelete;
	private teJLabel lblSearch;
	private teJTextField txtsearchName;
	private teJLabel lblAll;
	private teJButton btnClrSearch;
	private String txtInactive;
	private Customers genericCusts = new Customers();
	private String lSQLAllCust = "select * from ictoosd.customers order by custlastname";
	private String lSQLActive = "select * from ictoosd.customers where (inactive = '0' or inactive is null) order by custlastname";
	private Vector<String> errorMsg = new Vector<String>();
	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				CustomerForm inst = new CustomerForm();
				//inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public CustomerForm() {
		super();
		initGUI();
	}
	public CustomerForm(teJFrame caller) {
		super(caller);
		initGUI();
	}

	private void initGUI() {
		try {
			{
				this.setTitle("Maintain Customers");
			}
			{
				this.setSize(781, 475);
			}
			{
				Customers lc = new Customers();
                Vector<String> vCust = lc.loadCustVector(lSQLAllCust);
                lstAll = new teJList(vCust);
                lstAll.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                lstAll.addListSelectionListener(new ListSelectionListener() 
                {
                        public void valueChanged(ListSelectionEvent le) 
                    {
                        	if (lstAll.getSelectedIndex() != -1)
                        	{
                                setCustDetail((Customers)lstAll.getSelectedValue());
                                btnAdd.setEnabled(false);
                                btnDelete.setEnabled(true);
                                btnUpdate.setEnabled(true);
                                btnPmts.setEnabled(true);
                                btnCC.setEnabled(true);
                        	}
                    }
                });

				JScrollPane sp = new JScrollPane(lstAll);
				getContentPane().add(sp);
				//lstAll.setModel(listModel);
				sp.setBounds(12, 47, 301, 323);
			}
			{
				lblAll = new teJLabel();
				getContentPane().add(lblAll);
				lblAll.setText("Customers");
				lblAll.setBounds(12, 27, 80, 14);
				lblAll.setHorizontalAlignment(SwingConstants.LEFT);
			}
			{
				lblSearch = new teJLabel();
				getContentPane().add(lblSearch);
				lblSearch.setText("Search for: ");
				lblSearch.setBounds(325, 27, 110, 14);
				lblSearch.setHorizontalAlignment(SwingConstants.LEFT);
			}
			{
				btnAdd = new teJButton();
				getContentPane().add(btnAdd);
				btnAdd.setText("Add");
				btnAdd.setBounds(327, 382, 87, 25);
				btnAdd.setToolTipText("Add a new Customer to the database, based on the information in the 'Your Selection' form on the right.");
				btnAdd.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						//validate the data in the detail fields
						boolean validCust = ValidateCustomer();
						if (validCust == true)
						{
							Customers c = new Customers();
	                        c.setCustFirstName(txtFName.getText());
	                        c.setCustLastName(txtLName.getText());
	                        c.setCustAddress(txtAddress.getText());
	                        c.setCustCity(txtCity.getText());
	                        c.setCustProvince(txtProv.getText());
	                        c.setCustPostalCode(txtPC.getText());
	                        c.setCustCountry(txtCountry.getText());
	                        c.setCustHomePhone(txtHPhone.getText());
	                        c.setCustBusPhone(txtBPhone.getText());
	                        c.setCustEmail(txtEMail.getText());
	                        Agents ca = (Agents)cboAgent.getSelectedItem();
	                        c.setAgentId(ca.getAgencyID());
	                        if (txtInactive == "true")
	                        {
	                        	c.setInactive("1");
	                        }
	                        else
	                        {
	                        	c.setInactive("0");
	                        }
	                        c.addCustomer();
	                        
	        				if (chkSearchInactive.isSelected())
	        				{
	        					refreshCustList(lSQLAllCust);
	        				}
	        				else
	        				{
	        					refreshCustList(lSQLActive);
	        				}
	        				//refreshCustList("select * from ICTOOSD.CUSTOMERS where CUSTOMERID = 135");
						}
						else
						{
							ListModel newLstAllModel = 
								new DefaultComboBoxModel(errorMsg);
							lstAll.setModel(newLstAllModel);
							//change colour of text to red #c62E04, rgb 198,42,3
							lstAll.setForeground(new java.awt.Color(198,42,3));

							//set the selection colour to the background so 
							//it doesn't look like anything's getting selected
							lstAll.setSelectionBackground(lstAll.getBackground());
							//set focusable to false
							lstAll.setFocusable(false);						}
					}
				});
			}
			{
				btnDelete = new teJButton();
				getContentPane().add(btnDelete);
				btnDelete.setText("Deactivate");
				btnDelete.setBounds(435, 382, 87, 25);
				btnDelete.setToolTipText("Deactivate the selected Customer.");
				btnDelete.setEnabled(false);
				btnDelete.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
                        Customers c = new Customers();
                        c.setCustomerId(Integer.parseInt(txtCustID.getText()));
                       	c.setInactive("1");
                        c.deleteCustomer();
        				if (chkSearchInactive.isSelected())
        				{
        					refreshCustList(lSQLAllCust);
        				}
        				else
        				{
        					refreshCustList(lSQLActive);
        				}
					}
				});
			}
			{
				btnClear = new teJButton();
				getContentPane().add(btnClear);
				btnClear.setText("Clear");
				btnClear.setBounds(653, 382, 87, 25);
				btnClear.setToolTipText("Clears all the information in the forms and refreshes the Customer list with all customers in the database.");
				btnClear.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						clearCustDetail();
        				if (chkSearchInactive.isSelected())
        				{
        					refreshCustList(lSQLAllCust);
        				}
        				else
        				{
        					refreshCustList(lSQLActive);
        				}
        				btnAdd.setEnabled(true);
        				btnDelete.setEnabled(false);
        				btnUpdate.setEnabled(false);
        				btnCC.setEnabled(false);
        				btnPmts.setEnabled(false);
					}
				});
			}
			{
				btnUpdate = new teJButton();
				getContentPane().add(btnUpdate);
				btnUpdate.setText("Update");
				btnUpdate.setBounds(544, 382, 87, 25);
				btnUpdate.setToolTipText("Update the selected Customer in the database.");
				btnUpdate.setEnabled(false);
				btnUpdate.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						//validate the data in the detail fields
						boolean validCust = ValidateCustomer();
						if (validCust == true)
						{
	                        Customers c = new Customers();
	                        c.setCustomerId(Integer.parseInt(txtCustID.getText()));
	                        c.setCustFirstName(txtFName.getText());
	                        c.setCustLastName(txtLName.getText());
	                        c.setCustAddress(txtAddress.getText());
	                        c.setCustCity(txtCity.getText());
	                        c.setCustProvince(txtProv.getText());
	                        c.setCustPostalCode(txtPC.getText());
	                        c.setCustCountry(txtCountry.getText());
	                        c.setCustHomePhone(txtHPhone.getText());
	                        c.setCustBusPhone(txtBPhone.getText());
	                        c.setCustEmail(txtEMail.getText());
	                        Agents ca = (Agents)cboAgent.getSelectedItem();
	                        c.setAgentId(ca.getAgentId());
	                        if (txtInactive == "true")
	                        {
	                        	c.setInactive("1");
	                        }
	                        else
	                        {
	                        	c.setInactive("0");
	                        }
	                        c.updateCustomer();
	        				if (chkSearchInactive.isSelected())
	        				{
	        					refreshCustList(lSQLAllCust);
	        				}
	        				else
	        				{
	        					refreshCustList(lSQLActive);
	        				}
	        				//refreshCustList("select * from ICTOOSD.CUSTOMERS where CUSTOMERID = 135");
	        				//change colour of text to dark, dark brown #2b2003, rgb 43,31,2
	        				lstAll.setForeground(new java.awt.Color(43,31,2));
	        						
	        				//reset the colour of the selection background
	        				lstAll.setSelectionBackground(new java.awt.Color(2,234,231));
	        				//set focusable back to true
	        				lstAll.setFocusable(true);
						}
						else
						{
							ListModel newLstAllModel = 
								new DefaultComboBoxModel(errorMsg);
							lstAll.setModel(newLstAllModel);
							//change colour of text to red #c62E04, rgb 198,42,3
							lstAll.setForeground(new java.awt.Color(198,42,3));

							//set the selection colour to the background so 
							//it doesn't look like anything's getting selected
							lstAll.setSelectionBackground(lstAll.getBackground());
							//set focusable to false
							lstAll.setFocusable(false);						}
					}
				});
			}
			{
				pnlSelected = new teJPanel();
				getContentPane().add(pnlSelected);
				pnlSelected.setBounds(325, 145, 415, 225);
				pnlSelected.setLayout(null);
				{
					txtCustID = new teJTextField();
					pnlSelected.add(txtCustID);
					txtCustID.setBounds(13, 21, 75, 18);
					txtCustID.setEnabled(false);
				}
				{
					txtLName = new teJTextField();
					pnlSelected.add(txtLName);
					txtLName.setBounds(94, 21, 171, 18);
				}
				{
					txtFName = new teJTextField();
					pnlSelected.add(txtFName);
					txtFName.setBounds(271, 21, 131, 18);
				}
				{
					txtAddress = new teJTextField();
					pnlSelected.add(txtAddress);
					txtAddress.setBounds(13, 59, 389, 18);
				}
				{
					txtCity = new teJTextField();
					pnlSelected.add(txtCity);
					txtCity.setBounds(13, 97, 159, 18);
				}
				{
					txtProv = new teJTextField();
					pnlSelected.add(txtProv);
					txtProv.setBounds(178, 97, 40, 18);
				}
				{
					txtPC = new teJTextField();
					pnlSelected.add(txtPC);
					txtPC.setBounds(224, 97, 84, 18);
				}
				{
					txtCountry = new teJTextField();
					pnlSelected.add(txtCountry);
					txtCountry.setBounds(314, 97, 88, 18);
				}
				{
					txtHPhone = new teJTextField();
					pnlSelected.add(txtHPhone);
					txtHPhone.setBounds(13, 135, 159, 18);
				}
				{
					txtBPhone = new teJTextField();
					pnlSelected.add(txtBPhone);
					txtBPhone.setBounds(184, 135, 152, 18);
				}
				{
					txtEMail = new teJTextField();
					pnlSelected.add(txtEMail);
					txtEMail.setBounds(13, 173, 389, 18);
				}
				{
					Agents a = new Agents();
					Vector<Object> va = a.agentsVector("select * from ictoosd.Agents order by agtlastname, agtfirstname");
					cboAgent = new teJComboBox(va);
//					cboAgent = new teJComboBox();
					pnlSelected.add(cboAgent);
					cboAgent.setBounds(72, 194, 328, 28);
				}
				{
					lblAgent = new teJLabel();
					pnlSelected.add(lblAgent);
					lblAgent.setText("Agent: ");
					lblAgent.setBounds(1, 203, 59, 14);
				}
				{
					lblEmail = new teJLabel();
					pnlSelected.add(lblEmail);
					lblEmail.setText("Customer Email:");
					lblEmail.setBounds(13, 159, 140, 14);
					lblEmail.setHorizontalAlignment(SwingConstants.LEFT);
				}
				{
					lblHPhone = new teJLabel();
					pnlSelected.add(lblHPhone);
					lblHPhone.setText("Home Phone:");
					lblHPhone.setBounds(13, 121, 103, 14);
					lblHPhone.setHorizontalAlignment(SwingConstants.LEFT);
				}
				{
					lblBPhone = new teJLabel();
					pnlSelected.add(lblBPhone);
					lblBPhone.setText("Business Phone:");
					lblBPhone.setBounds(184, 121, 109, 14);
				}
				{
					lblCity = new teJLabel();
					pnlSelected.add(lblCity);
					lblCity.setText("City:");
					lblCity.setBounds(13, 83, 87, 14);
					lblCity.setHorizontalAlignment(SwingConstants.LEFT);
				}
				{
					lblProv = new teJLabel();
					pnlSelected.add(lblProv);
					lblProv.setText("Prov:");
					lblProv.setBounds(178, 83, 34, 14);
				}
				{
					lblPC = new teJLabel();
					pnlSelected.add(lblPC);
					lblPC.setText("Postal Code:");
					lblPC.setBounds(224, 83, 84, 14);
				}
				{
					lblCountry = new teJLabel();
					pnlSelected.add(lblCountry);
					lblCountry.setText("Country:");
					lblCountry.setBounds(314, 83, 74, 14);
					lblCountry.setHorizontalAlignment(SwingConstants.LEFT);
				}
				{
					lblAddress = new teJLabel();
					pnlSelected.add(lblAddress);
					lblAddress.setText("Address:");
					lblAddress.setBounds(13, 45, 56, 14);
				}
				{
					lblID = new teJLabel();
					pnlSelected.add(lblID);
					lblID.setText("Cust ID:");
					lblID.setBounds(13, 8, 53, 14);
				}
				{
					lblLName = new teJLabel();
					pnlSelected.add(lblLName);
					lblLName.setText("Last Name:");
					lblLName.setBounds(94, 8, 84, 14);
					lblLName.setHorizontalAlignment(SwingConstants.LEFT);
				}
				{
					lblFName = new teJLabel();
					pnlSelected.add(lblFName);
					lblFName.setText("First Name:");
					lblFName.setBounds(271, 8, 107, 14);
					lblFName.setHorizontalAlignment(SwingConstants.LEFT);
				}
				{
					chkInactive = new JCheckBox();
					pnlSelected.add(chkInactive);
					chkInactive.setBounds(356, 130, 22, 23);
					chkInactive.setBackground(new java.awt.Color(251,253,242));
					chkInactive.addItemListener(new ItemListener() {
						public void itemStateChanged(ItemEvent evt) {
							if (evt.getStateChange() == ItemEvent.SELECTED)
							{
								txtInactive = "true";
							}
							else
							{
								txtInactive = "false";
							}
						}
					});
				}
				{
					lblInactive = new teJLabel();
					pnlSelected.add(lblInactive);
					lblInactive.setText("Inactive");
					lblInactive.setBounds(336, 118, 57, 14);
				}
		}
			{
				lblSelectedPanel = new teJLabel();
				getContentPane().add(lblSelectedPanel);
				lblSelectedPanel.setText("Your Selection:");
				lblSelectedPanel.setBounds(325, 131, 101, 14);
				lblSelectedPanel.setHorizontalAlignment(SwingConstants.LEFT);
			}
			{
				pnlSearch = new teJPanel();
				getContentPane().add(pnlSearch);
				pnlSearch.setBounds(325, 48, 415, 78);
				pnlSearch.setLayout(null);
				{
					txtsearchName = new teJTextField();
					pnlSearch.add(txtsearchName);
					txtsearchName.setBounds(116, 4, 208, 21);
				}
				{
					btnGo = new teJButton();
					pnlSearch.add(btnGo);
					btnGo.setText("Search");
					btnGo.setBounds(328, 7, 77, 22);
					btnGo.setToolTipText("Searches the Customers table for customers that match the parameters in the search panel.");
					btnGo.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							String lsql = "select * from ICTOOSD.CUSTOMERS " +
							  			  "where 1 = 1";
							if (txtsearchName.getText() != "")
							{
								lsql += " and (CUSTFIRSTNAME like '%" + txtsearchName.getText() + "%'" +
										   " or CUSTLASTNAME like '%" + txtsearchName.getText() + "%')";
							}
							if (txtsearchDesc.getText() != "")
							{
								lsql += " and CUSTHOMEPHONE like '%" + txtsearchDesc.getText() + "%'";
							}
							lsql += " order by CUSTLASTNAME";
							refreshCustList(lsql);
						}
					});
				}
				{
					btnClrSearch = new teJButton();
					pnlSearch.add(btnClrSearch);
					btnClrSearch.setText("Clear");
					btnClrSearch.setBounds(328, 32, 77, 22);
					btnClrSearch.setToolTipText("Clears the text fields in the search panel.");
					btnClrSearch.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							txtsearchName.setText("");
							txtsearchDesc.setText("");
	        				if (chkSearchInactive.isSelected())
	        				{
	        					refreshCustList(lSQLAllCust);
	        				}
	        				else
	        				{
	        					refreshCustList(lSQLActive);
	        				}
						}
					});
				}
				{
					lblsearchName = new teJLabel();
					pnlSearch.add(lblsearchName);
					lblsearchName.setText("Name: ");
					lblsearchName.setBounds(52, 13, 64, 14);
				}
				{
					txtsearchDesc = new teJTextField();
					pnlSearch.add(txtsearchDesc);
					txtsearchDesc.setBounds(116, 33, 208, 21);
				}
				{
					lblsearchDesc = new teJLabel();
					pnlSearch.add(lblsearchDesc);
					lblsearchDesc.setText("Home Phone: ");
					lblsearchDesc.setBounds(12, 40, 103, 14);
				}
				{
					chkSearchInactive = new JCheckBox();
					pnlSearch.add(chkSearchInactive);
					chkSearchInactive.setBounds(115, 58, 37, 19);
					chkSearchInactive.setBackground(new java.awt.Color(251,253,242));
					chkSearchInactive.setSelected(true);
					chkSearchInactive.setToolTipText("Check this box to see both active and inactive customers");
					chkSearchInactive.addItemListener(new ItemListener() {
						public void itemStateChanged(ItemEvent evt) {
	        				if (chkSearchInactive.isSelected())
	        				{
	        					refreshCustList(lSQLAllCust);
	        				}
	        				else
	        				{
	        					refreshCustList(lSQLActive);
	        				}
						}
					});
				}
				{
					lblShowInactive = new teJLabel();
					pnlSearch.add(lblShowInactive);
					lblShowInactive.setText("Inactive: ");
					lblShowInactive.setBounds(45, 60, 67, 14);
				}
				{
					btnUnassigned = new teJButton();
					pnlSearch.add(btnUnassigned);
					btnUnassigned.setText("Unassigned Customers Only");
					btnUnassigned.setBounds(186, 59, 219, 18);
					btnUnassigned.setToolTipText("See only customers who do not have an agent assigned");
					btnUnassigned.addMouseListener(new MouseAdapter() {
						public void mouseClicked(MouseEvent evt) {
							String lsql = "select * from ictoosd.customers where (inactive='0' or inactive is null) and agentid is null";
							Vector<String> newCust = genericCusts.loadCustVector(lsql);
							ListModel newLstAllModel = 
								new DefaultComboBoxModel(newCust);
							lstAll.setModel(newLstAllModel);
							
						}
					});
				}
			}
			{
				btnPmts = new teJButton();
				getContentPane().add(btnPmts);
				btnPmts.setText("Manage Bookings & Payments");
				btnPmts.setBounds(327, 419, 217, 25);
				btnPmts.setToolTipText("Manage the bookings and payments for the selected customer.");
				btnPmts.setEnabled(false);
				btnPmts.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						//System.out.println(txtCustID.getText());
						//BookingPmtsForm inst = new BookingPmtsForm(txtCustID.getText());
						//inst.setLocationRelativeTo(null);
						//inst.setVisible(true);
                        newWindow(new BookingPmtsForm(txtCustID.getText()));
					}
				});
			}
			{
				btnCC = new teJButton();
				getContentPane().add(btnCC);
				btnCC.setText("Manage Credit Card");
				btnCC.setBounds(582, 419, 158, 25);
				btnCC.setToolTipText("Manage the credit card information for the selected customer");
				btnCC.setEnabled(false);
				btnCC.addMouseListener(new MouseAdapter() {
					public void mouseClicked(MouseEvent evt) {
						//MngCreditCardForm inst = new MngCreditCardForm(txtCustID.getText());
						//inst.setLocationRelativeTo(null);
						//inst.setVisible(true);
                        newWindow(new MngCreditCardForm(txtCustID.getText()));
					}
				});
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

    private void setCustDetail(Customers cust) 
    {
            Customers c = cust;
            txtCustID.setText(Integer.toString(c.getCustomerId()));
            txtLName.setText(c.getCustLastName());
            txtFName.setText(c.getCustFirstName());
            txtAddress.setText(c.getCustAddress());
            txtCity.setText(c.getCustCity());
            txtProv.setText(c.getCustProvince());
            txtPC.setText(c.getCustPostalCode());
            txtCountry.setText(c.getCustCountry());
            txtHPhone.setText(c.getCustHomePhone());
            txtBPhone.setText(c.getCustBusPhone());
            txtEMail.setText(c.getCustEmail());
            cboAgent.setSelectedIndex(c.getAgentId());
            if (c.getInactive() == "true")
            {
            	chkInactive.setSelected(true);
            }
            else
            {
            	chkInactive.setSelected(false);
            }
    }
    
    private void clearCustDetail()
    {
        txtCustID.setText("");
        txtLName.setText("");
        txtFName.setText("");
        txtAddress.setText("");
        txtCity.setText("");
        txtProv.setText("");
        txtPC.setText("");
        txtCountry.setText("");
        txtHPhone.setText("");
        txtBPhone.setText("");
        txtEMail.setText("");
        cboAgent.setSelectedIndex(0);
        chkInactive.setSelected(false);
    }

	private void refreshCustList(String sql)
	{
		//lstAll.clearSelection();
		Vector<String> newCustVector = genericCusts.loadCustVector(sql);
		
		ListModel newLstAllModel = 
			new DefaultComboBoxModel(newCustVector);
		lstAll.setModel(newLstAllModel);
		//change colour of text to dark, dark brown #2b2003, rgb 43,31,2
		lstAll.setForeground(new java.awt.Color(43,31,2));
				
		//reset the colour of the selection background
		lstAll.setSelectionBackground(new java.awt.Color(2,234,231));
		//set focusable back to true
		lstAll.setFocusable(true);
	}

	private boolean ValidateCustomer()
	{
		errorMsg.clear();
		boolean b = true;
		if (Validate.genericText(txtFName.getText()) == false)
		{
			errorMsg.addElement("First Name is invalid");
			b = false;
		}
		if (Validate.genericText(txtLName.getText()) == false)
		{
			errorMsg.addElement("Last Name is invalid");
			b = false;
		}
		
		if (Validate.genericText(txtAddress.getText()) == false)
		{
			errorMsg.addElement("Address is invalid");
			b = false;
		}
		
		if (Validate.genericText(txtCity.getText()) == false)
		{
			errorMsg.addElement("City is invalid");
			b = false;
		}
		
		if (Validate.isValidISOCode(txtProv.getText()) == false)
		{
			errorMsg.addElement("Province/State is invalid");
			b = false;
		}
		
		if (Validate.isValidPostalZip(txtPC.getText()) == false)
		{
			errorMsg.addElement("Postal/Zip code is invalid");
			b = false;
		}
		
		if (Validate.genericText(txtCountry.getText()) == false)
		{
			errorMsg.addElement("Country is invalid");
			b = false;
		}

		if (Validate.isValidPhoneFax(txtHPhone.getText()) == false)
		{
			errorMsg.addElement("Home phone number is invalid");
			b = false;
		}
		if (Validate.isValidPhoneFax(txtBPhone.getText()) == false)
		{
			errorMsg.addElement("Business phone number is invalid");
			b = false;
		}
		if (Validate.isValidEmail(txtEMail.getText()) == false)
		{
			errorMsg.addElement("Email address is invalid");
			b = false;
		}
		return b;
	}	

    private void newWindow(teJinternalFrame newWin)
    {
    	MainMDIForm temp = (MainMDIForm)getTopLevelAncestor();
    	temp.addWin(newWin);
    }
}
